package com.ids.actions;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.ids.bean.EmployeeAttendanceStatistics;
import com.ids.service.EmployeeAttendanceScreenService;
import com.ids.util.Utlity;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;


public class EmployeeAttendanceScreen extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private Map<String, EmployeeAttendanceStatistics> employeeAttandence;
    int month;
    int year;
		
	
	
	public String execute() throws Exception {
//		Map<String, Object> session = ActionContext.getContext().getSession();
//		final String empCode = (String) session.get("empCode");
//		employeeAttandence = EmployeeAttendanceScreenService.getInstance()
//		.getEmployeeAttandence(empCode);
		return getSpecificMonthData();
	}
//	public String getMultilevelEmployeeData() {
//		HttpServletRequest request = ServletActionContext.getRequest();
//		Map<String, Object> session = ActionContext.getContext().getSession();
//		final String empCode = (String) session.get("empCode");
//		String forward = "success";
//		boolean getMultiLevel = false;
//		String isMultilevel = (request.getParameter("isMultiLevelValue"));
//		if(null!=isMultilevel){
//			getMultiLevel = Boolean.parseBoolean(isMultilevel);
//		}
//		employeeAttandence = EmployeeAttendanceScreenService.getInstance()
//		.getEmployeeAttandence(empCode,getMultiLevel);
//		request.setAttribute("MultiLevevelEmployeeAttandence",employeeAttandence);
//		System.out.println(isMultilevel);
//		return forward;
//	}
	public String getSpecificMonthData() {
		HttpServletRequest request = ServletActionContext.getRequest();
		Map<String, Object> session = ActionContext.getContext().getSession();
		boolean isMultiLevel = false;
		final String empCode = (String) session.get("empCode");
		String monthSelection = request.getParameter("monthSelection");
		String yearSelection = request.getParameter("yearSelection");
		String isMultilevelInReq = request.getParameter("isMultiLevelValue");

		if(null!=monthSelection){
			month = Integer.parseInt(monthSelection);
			
		}else{
			month =new Date().getMonth() + 1;
			
		}
		if (null!=yearSelection){
			year = Integer.parseInt(yearSelection);
		}else{     
			
			year = new Date().getYear() + 1900;
		}
		
		if(null!=isMultilevelInReq){
			isMultiLevel = Boolean.parseBoolean(isMultilevelInReq);
		}
		employeeAttandence = EmployeeAttendanceScreenService.getInstance()
		.getEmployeeAttandence(empCode,isMultiLevel,month,year);
		String forward = "success";
		
		return forward;
	}

	public Map<String, EmployeeAttendanceStatistics> getEmployeeAttandence() {
		return employeeAttandence;
	}

	public void setEmployeeAttandence(
		Map<String, EmployeeAttendanceStatistics> employeeAttandenceData) {
		this.employeeAttandence = employeeAttandenceData;
	}

	public int[] getMonths() {
		
		return	Utlity.displayMonthDays(month, year);

	}

	public List<String> getWeekDays() {
		return Utlity.displayWeekDays(month, year);
	}
	public List<String> getAttendanceStatistics() {
		return Utlity.displayAttendanceStatistics();
	}

	public String getMonthMM() {
		return Utlity.getMonthMM();
	}

}
